package priv.pront.code.national.acwing.graph;

import java.util.Arrays;
import java.util.Scanner;
/*树的直径： 任意一点x出发到距离最长的点y ，再从y 出发到达的距离y最长的点z , yz便是这个树 / 图的 直径*/
public class A1207_大臣的旅费 {
    static int N = 100010, M = 200010 ,idx;
    static int[] h = new int[N];
    static int[] e = new int[M];
    static int[] ne = new int[M];
    static int[] w = new int[M];
    static int[] dis = new int[N];

    static void add(int a, int b, int c){
        e[idx] = b; w[idx] = c; ne[idx] = h[a]; h[a] = idx++;
    }

    static void dfs(int u, int father, int distance){
        dis[u] = distance;
        for(int i = h[u]; i != -1; i = ne[i]){
            int j = e[i];
            if(j != father) dfs(j, u, distance + w[i]);
        }
    }

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Arrays.fill(h, -1);
        for(int i = 0; i < n - 1; i++){
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int c = scanner.nextInt();
            add(a, b, c);
            add(b, a, c);
        }
        //找到任意点x找到距离最远的点y
        dfs(1, -1, 0);
        int u = 1;
        for(int i = 2; i <= n; i++){
            if(dis[i] > dis[u]) u = i;
        }
        //找到离y最远的点的距离
        dfs(u, -1, 0);
        int maxv = dis[1];
        for(int i = 2; i <= n; i++){
            if(dis[i] > maxv) maxv = dis[i];
        }
        System.out.println(maxv * 10 + ((long)(maxv + 1) * maxv ) / 2);
    }
}
